package com.lsl.builder_pattern.practice.practice2;

/**
 * 确保调用makeString方法、makeItems方法和close方法之前必须且只能调用一次makeTitle方法
 * 使用 Builder模式和Template模式相结合
 *
 * @author Zed
 * @description
 * @date 2022/11/27 16:47
 */
public abstract class Builder {
    private boolean flag = false;

    public void makeTitle(String title) {
        if (!flag) {
            buildTitle(title);
            flag = true;
        }
    }


    public void makeString(String str) {
        if (flag) {
            buildString(str);
        }
    }


    public void makeItems(String[] items) {
        if (flag) {
            buildItems(items);
        }
    }


    public void close() {
        if (flag) {
            buildClose();
        }
    }


    protected abstract void buildTitle(String title);

    protected abstract void buildString(String str);

    protected abstract void buildItems(String[] items);

    protected abstract void buildClose();
}
